package com.example.example02;

import java.io.IOException;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

public class SpeakDurationMapper extends Mapper<LongWritable,Text,Text,SpeakBean> {
  private final String LINE_SPLITER = "\t";
  private final Text textWriter = new Text();
  private final SpeakBean speakBean = new SpeakBean();

  @Override
  public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException{
    String strLine = value.toString();
    if(strLine == null || strLine.length() < 1)
      return;
    String[] fileds = strLine.split(this.LINE_SPLITER);
    if(fileds.length < 4)
      return;
    String deviceId = fileds[0];
    long duration = Long.parseLong(fileds[1]);
    long thirdPartDuration = Long.parseLong(fileds[2]);
    long sumDuration = Long.parseLong(fileds[3]);
    this.speakBean.set(duration,thirdPartDuration,sumDuration);
    this.textWriter.set(deviceId);
    context.write(this.textWriter, this.speakBean);
  }
}
